from django.contrib.auth import authenticate
from rest_framework import status
from rest_framework.viewsets import ModelViewSet, ViewSet
import requests
from tsl_backend.fgr_api.middleware import response
from tsl_backend.users.models import User, Account
import tsl_backend.jwt as jwt

import logging

# noinspection

class AuthView(ViewSet):
    # FGR send request for authentication
    @staticmethod
    def getToken(request):
        logging.info(f"FGR login: {request.data['username']}")
        token = jwt.get_tokens_for_fgr(request.data["username"], request.data["password"])
        if token is not None:
            return response(
                code=status.HTTP_200_OK,
                message="登陸成功",
                data=token["access_token"],
            )
        else:
            return response(
                code=status.HTTP_401_UNAUTHORIZED,
                message="登陸失敗",
            )
        